package com.itheima.controller;

import com.itheima.aop.Log;
import com.itheima.entity.Clazz;
import com.itheima.entity.ClazzsQueryParam;
import com.itheima.entity.PageBean;
import com.itheima.entity.Result;
import com.itheima.service.ClazzsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description ClazzsController
 * @Author 你的名字拼接或昵称
 * @Date 2025-09-06
 */
@Slf4j
@RestController
@RequestMapping("/clazzs")
public class ClazzsController {

    @Autowired
    private ClazzsService clazzsService;

    //分页查询
    @GetMapping
    public Result page(ClazzsQueryParam clazzsQueryParam){
        PageBean pageBean=clazzsService.page(clazzsQueryParam);
        return Result.success(pageBean);
    }

    //新增班级
    @Log
    @PostMapping
    public Result save(@RequestBody Clazz clazz){
        clazzsService.save(clazz);
        return Result.success();
    }

    //根据id查询
    @GetMapping("/{id}")
    public Result getId(@PathVariable Integer id){
        Clazz clazz=clazzsService.getId(id);
        return Result.success(clazz);
    }

    //修改班级信息
    @Log
    @PutMapping
    public  Result update(@RequestBody Clazz clazz){
        clazzsService.update(clazz);
        return  Result.success();
    }

    //删除班级信息
    @Log
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        clazzsService.delete(id);
        return Result.success();
    }

    //查询所有班级
    @GetMapping("/list")
    public Result getlist(){
        List<Clazz> clazzList=clazzsService.getlist();
        return Result.success(clazzList);
    }
}
